
/****** Object:  Table [dbo].[#SRCNAME#_Document]     ******/
CREATE TABLE [dbo].[#SRCNAME#_Document](
	[Id] [int] NOT NULL,
	[Name] [char](255) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
 CONSTRAINT [PK_#SRCNAME#_Document] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


/****** Object:  Table [dbo].[#SRCNAME#_Path]     ******/
CREATE TABLE [dbo].[#SRCNAME#_Path](
	[PathId] [int] NOT NULL,
	[PathExp] [varchar](500) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
 CONSTRAINT [PK_#SRCNAME#_Path] PRIMARY KEY CLUSTERED 
(
	[PathId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

CREATE UNIQUE NONCLUSTERED INDEX [IX_Path] ON [dbo].[#SRCNAME#_Path] 
(
	[PathExp] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]


/****** Object:  Table [dbo].[#SRCNAME#_DocumentRValue]    ******/
CREATE TABLE [dbo].[#SRCNAME#_DocumentRValue](
	[DocId] [int] NOT NULL,
	[Level] [int] NOT NULL,
	[RValue] [bigint] NULL,
	[AncestorValue] [bigint] NULL,
 CONSTRAINT [PK_#SRCNAME#_DocumentRValue] PRIMARY KEY CLUSTERED 
(
	[DocId] ASC,
	[Level] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


/****** Object:  Table [dbo].[#SRCNAME#_PathValue]     ******/
CREATE TABLE [dbo].[#SRCNAME#_PathValue](
	[DocId] [int] NOT NULL,
	[LeafOrder] [int] NOT NULL,
	[BranchOrder] [int] NULL,
	[PathId] [int] NULL,
	[AncestorDeweyGroup] [bigint] NOT NULL,
	[SiblingSum] [bigint] NULL,
	[LeafValue] [varchar](512) COLLATE SQL_Latin1_General_CP1_CS_AS NULL
) ON [PRIMARY]

CREATE UNIQUE CLUSTERED INDEX [IX_PathValue_1] ON [dbo].[#SRCNAME#_PathValue] 
(
	[DocId] ASC,
	[PathId] ASC,
	[AncestorDeweyGroup] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = OFF) ON [PRIMARY]

CREATE NONCLUSTERED INDEX [IX_PathValue_2] ON [dbo].[#SRCNAME#_PathValue] 
(
	[PathId] ASC,
	[BranchOrder] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]

CREATE NONCLUSTERED INDEX [IX_PathValue_3] ON [dbo].[#SRCNAME#_PathValue] 
(
	[PathId] ASC,
	[LeafValue] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]


/****** Object:  Table [dbo].[Attribute]     ******/
CREATE TABLE [dbo].[#SRCNAME#_Attribute](
	[DocId] [int] NOT NULL,
	[AncestorDeweyGroup] [bigint] NOT NULL,
	[PathId] [int] NOT NULL,
	[LeafValue] [varchar](512) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL
) ON [PRIMARY]

CREATE UNIQUE CLUSTERED INDEX [IX_Attribute_1] ON [dbo].[#SRCNAME#_Attribute] 
(
	[DocId] ASC,
	[AncestorDeweyGroup] ASC,
	[PathId] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = OFF) ON [PRIMARY]

CREATE NONCLUSTERED INDEX [IX_Attribute_2] ON [dbo].[#SRCNAME#_Attribute] 
(
	[PathId] ASC,
	[LeafValue] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]




/****** Object:  Table [dbo].[TextContent]     ******/
CREATE TABLE [dbo].[#SRCNAME#_TextContent](
	[DocId] [int] NOT NULL,
	[LeafOrder] [int] NOT NULL,
	[BranchOrder] [int] NULL,
	[PathId] [int] NULL,
	[AncestorDeweyGroup] [bigint] NOT NULL,
	[SiblingSum] [bigint] NULL,
	[LeafValue] [varchar](max) COLLATE SQL_Latin1_General_CP1_CS_AS NULL
) ON [PRIMARY]

CREATE UNIQUE CLUSTERED INDEX [IX_TextContent_1] ON [dbo].[#SRCNAME#_TextContent] 
(
	[DocId] ASC,
	[PathId] ASC,
	[AncestorDeweyGroup] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = OFF) ON [PRIMARY]


/****** Object:  Table [dbo].[AttrContent]     ******/
CREATE TABLE [dbo].[#SRCNAME#_AttrContent](
	[DocId] [int] NOT NULL,
	[AncestorDeweyGroup] [bigint] NOT NULL,
	[PathId] [int] NOT NULL,
	[LeafValue] [varchar](max) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL
) ON [PRIMARY]

CREATE UNIQUE CLUSTERED INDEX [IX_AttrContent_1] ON [dbo].[#SRCNAME#_AttrContent] 
(
	[DocId] ASC,
	[AncestorDeweyGroup] ASC,
	[PathId] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = OFF) ON [PRIMARY]

/****** Statistics Table     ******/
/****** Object:  Table [dbo].[#SRCNAME#_PathCount_ValueSelectivity]     ******/
CREATE TABLE [dbo].[#SRCNAME#_PathCount_ValueSelectivity](
	[pathid] [int] NULL,
	[CP] [int] NULL,
	[VP] [int] NULL
) ON [PRIMARY]

/****** Object:  Table [dbo].[#SRCNAME#_TotalPathCount]   ******/
CREATE TABLE [dbo].[#SRCNAME#_TotalPathCount](
	[T] [int] NULL
) ON [PRIMARY]


CREATE TABLE [dbo].[#SRCNAME#_PVTemp](
	[LeafValue] [varchar](MAX)  COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
	[PathID] [int] NULL,
	[BranchOrder] [int] NULL,
	[DeweyOrderSum] [bigint] NULL,
	[DocId] [int] NULL,
	[LeafOrder] [int] NULL
) ON [PRIMARY]


CREATE NONCLUSTERED INDEX [DocID_LeafOrder] ON [dbo].[#SRCNAME#_PVTemp] 
(
	[LeafOrder] ASC,
	[DocId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]


CREATE TABLE [dbo].[#SRCNAME#_DescendantTemp](
	[DescendantId] [int] NOT NULL,
	[PathId] [int] NOT NULL,
	[Level] [int] NOT NULL,
 CONSTRAINT [PK_#SRCNAME#_DescendantTemp] PRIMARY KEY CLUSTERED 
(
	[PathId] ASC,
	[DescendantId] ASC,
	[Level] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


CREATE TABLE [dbo].[#SRCNAME#_AncestorTemp](
	[PathId] [int] NOT NULL,
	[AncestorId] [int] NOT NULL,
	[Level] [int] NOT NULL,
	[AnceBranchOrd] [int] NOT NULL,
 CONSTRAINT [PK_#SRCNAME#_AncestorTemp] PRIMARY KEY CLUSTERED 
(
	[PathId] ASC,
	[AncestorId] ASC,
	[Level] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


CREATE TABLE [dbo].[#SRCNAME#_LastTemp](
	[RID] [int] NOT NULL,
	[DocID] [int] NOT NULL,
	[SiblingSum] [bigint] NOT NULL,
	[Flag] [smallint] NOT NULL,
	[DeweyOrderSum] [bigint] NULL,
	[PDOS] [bigint] NULL
) ON [PRIMARY]


CREATE CLUSTERED INDEX [Idx] ON [dbo].[#SRCNAME#_LastTemp] 
(
	[Flag] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]


/****** Object:  Table [dbo].[#SRCNAME#_CardinalityInfo]     ******/
CREATE TABLE [dbo].[#SRCNAME#_CardinalityInfo](
	[LastDocID] [int] NOT NULL,
	[NodeName] [varchar](255) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
	[PathExp] [varchar](512) COLLATE SQL_Latin1_General_CP1_CS_AS NULL
) ON [PRIMARY]
